var Layer = {
	Image: function(){
		var obj = this;
		obj.id = this.id || null;
		obj.callId = this.callId || null;
		obj.ImgW = this.ImgW || 0;
		obj.ImgH = this.ImgH || 0;
		obj.ImageW = this.ImageW || 0;
		obj.ImageH = this.ImageH || 0;
		obj.top = this.top || 30;
		obj.PageEvent = this.PageEvent || false;
		obj.Speed = this.Speed || 'slow';
		obj.pic = $(obj.callId).find("img");
		$(obj.id).css("cursor","pointer").click(function(e){  
			new function(){
				obj.htmlH = document.body.offsetHeight;
				obj.bodyW = document.body.clientWidth;
				obj.bodyT = document.body.scrollTop || document.documentElement.scrollTop;
				window.onresize = function(){
					obj.htmlH = $("html").outerHeight();
					obj.bodyW = document.body.clientWidth;
					obj.bodyT = document.body.scrollTop || document.documentElement.scrollTop;
					if(!obj.locking) return false;
					var ImgH = obj.Img.outerHeight();
					var ItemT = obj.Item.position().top;
					obj.locking.css({
						"height": ImgH>obj.htmlH? (ImgH+obj.top+10): obj.htmlH +"px"
					}).next().animate({
						"left": parseInt(obj.bodyW/2)-parseInt(obj.Img.width()/2) +"px"
					},obj.Speed);
				}
			}             
			obj.Item = $('<div/>').prependTo(document.body)
			.css({
				"position":"absolute",
				//"top": $(this).position().top+10,
				//"left": $(this).position().left+10,
				"top": e.pageY,
				"left": e.pageX,
				"width":50,
				"height":10,
				"text-align":"center",
				"border":"#DDD 5px solid",
				"overflow":"hidden",
				"z-index":1002,
				"background":"#FFF url(css/cur/loading.gif) no-repeat center center"
			});
			obj.locking = $('<div/>').prependTo(document.body).css({
				"position":"absolute",
				"top":0,
				"left":0,
				"width":"100%",
				"background-color":"#000",
				"opacity": 0.0,
				"z-index":1000
			});
			
			obj.Img = $('<img/>').appendTo(obj.Item).attr("src",this.src).val(0).css({
				"margin":"auto",
				"width": obj.ImageW ? obj.ImageW :"auto",
				"height": obj.ImageH ? obj.ImageH :"auto",
				"display":"block",
				"background-color":"#FFF"
			}).hide();
			if(obj.ImgW && !obj.ImageW){if(obj.Img.width() > obj.ImgW){ obj.Img.width(obj.ImgW); }}
			if(obj.ImgH && !obj.ImageH){if(obj.Img.height() > obj.ImgH){ obj.Img.height(obj.ImgH); }}
			obj.Item.animate({
				"width": obj.Img.outerWidth(),
				"top": obj.bodyT+obj.top,
				"left": parseInt(obj.bodyW/2)-parseInt(obj.Img.width()/2) +"px",
				"height": obj.Img.outerHeight()
			},"slow",function(){ 
				obj.Img.show(); 
			});
			obj.locking.css({
				"height": obj.Img.outerHeight()>obj.htmlH? (obj.Img.outerHeight()+obj.top+10): obj.htmlH +"px"
			})
			.click(function(){
				window.onresize = null;
				obj.Item.fadeOut(obj.Speed,function(){
					$(this).remove();
					obj.locking.fadeOut(obj.Speed,function(){$(this).remove()});
				});
			})
			.animate({"opacity":0.2},obj.Speed);
	
			if(obj.PageEvent){
				obj.Img.click(function(e){
					var num = e.pageX < (obj.bodyW/2)? parseInt(obj.Img.val())-1 : parseInt(obj.Img.val())+1;
					if(num < 0 || num >= obj.pic.length){ return false; }
					obj.Img.attr("src",obj.pic.eq(num).attr('src')).val(num)
					.css({
						"width": obj.ImageW ? obj.ImageW : "auto",
						"height": obj.ImageH ? obj.ImageH :"auto"
					}).hide();
					if(obj.ImgW && !obj.ImageW){if(obj.Img.width() > obj.ImgW){ obj.Img.width(obj.ImgW); }}
					if(obj.ImgH && !obj.ImageH){if(obj.Img.height() > obj.ImgH){ obj.Img.height(obj.ImgH); }}
					
					obj.Item.animate({
						"width": obj.Img.outerWidth(),
						"height": obj.Img.outerHeight(),
						"left": (parseInt(obj.bodyW/2)-parseInt(obj.Img.width()/2)) +"px"
					},obj.Speed,function(){
						obj.Img.show();		
					});
					obj.locking.css({
						"height": obj.Img.outerHeight()>obj.htmlH? (obj.Img.outerHeight()+obj.top+10): obj.htmlH +"px"
					});
				}).mousemove(function(e){
					var num = parseInt(this.value);
					$(this)
					.css({"cursor": e.pageX < (obj.bodyW/2)?"url(css/cur/pre.ico),auto" : "url(css/cur/next.ico),auto"})
					.attr("title",e.pageX < (obj.bodyW/2)?"上一张:"+ BNext(num-1) : "下一张:"+ BNext(num+1));
				});
				function BNext(n){
					return (n < 0 || n >= obj.pic.length)? "没有了" : obj.pic.eq(n).attr("alt");
				}
			}
		})
	}
}